package com.foton.bpc.all.remoting.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.concurrent.atomic.AtomicLong;

/**
 * @Author RenPu
 * @Date 2023/6/6 9:33
 * @Version 1.0
 * @Description: 请求实体对象
 **/


@Builder
@Data
@AllArgsConstructor
public class BpcInvacation implements Serializable {

    private static final long serialVersionUID=3336021432713606929L;

    private long id;

    static AtomicLong SEO =new AtomicLong();

    private String serviceName;

    private String methodName;

    private Class[] paramTypes;

    private Object[] arguments;

    public BpcInvacation() {

        setId(incrementAndGet());
    }

    private long incrementAndGet() {
        long current;
        long next;

        //如果获取的SEO的当前值，大于2147483647则进行归零，重新循环生成，同时新值next不能替换current也进行重新生成值
        do {
            current = SEO.get();
            next = current > 2147483647 ? 0 : current + 1;
        } while (!SEO.compareAndSet(current, next));

        return next;
    }

}
